package link.chengguo.orangemall.modules.quartz.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import link.chengguo.orangemall.enums.OrderInfoEnum;
import link.chengguo.orangemall.enums.OrderStatusEnum;
import link.chengguo.orangemall.modules.order.domain.OrangeStoreOrder;
import link.chengguo.orangemall.modules.order.service.OrangeStoreOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.List;

/**
 * @Author: mxchen
 * @Date: 2020/11/11 17:14
 */
@Slf4j
@Component
public class OrderTask {

    @Autowired
    private OrangeStoreOrderService storeOrderService;

    public void run(String day){
        LocalDate now = LocalDate.now();
        now = now.minusDays(Integer.valueOf(day));
        QueryWrapper<OrangeStoreOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(OrangeStoreOrder::getStatus, OrderInfoEnum.STATUS_1.getValue()).eq(OrangeStoreOrder::getRefundStatus,0).lt(OrangeStoreOrder::getPayTime,now);
        List<OrangeStoreOrder> orders = storeOrderService.list(queryWrapper);
        for (OrangeStoreOrder order : orders) {
            storeOrderService.takeOrder(order.getOrderId(),order.getUid());
            log.info("自动确认收货订单id:"+order.getOrderId());
        }
    }
}
